package com.example.sicnuaccountingapp.base

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map

abstract class BaseRepository {
    protected fun <T> Flow<T>.handleErrors(): Flow<Result<T>> {
        return this.map { Result.success(it) }
            .catch { emit(Result.failure(it)) }
    }

    protected suspend fun <T> safeCall(block: suspend () -> T): Result<T> {
        return try {
            Result.success(block())
        } catch (e: Exception) {
            Result.failure(e)
        }
    }
} 